import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { STColumn, STComponent, STData, STRequestOptions } from '@delon/abc/st';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { AdviceFeedbackService } from '../../services/advice-feedback.service';

@Component({
  selector: 'app-parter-advice-feedback',
  templateUrl: './list.component.html'
})
export class ParterAdviceFeedbackListComponent implements OnInit {
  schema: SFSchema = {};
  columns1!: STColumn[];
  columns2!: STColumn[];
  @ViewChild('st1', { static: false })
  st1!: STComponent;
  ui!: SFUISchema;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  _$expand = false;
  selectedIndex = 0;

  data = [{ name1: 1111 }];
  constructor(public router: Router, public service: AdviceFeedbackService) {}

  /**
   * 查询参数
   */
  get reqParams() {
    return { ...this.sf?.value };
  }
  /**
   * 查询字段个数
   */
  get queryFieldCount(): number {
    return Object.keys(this.schema?.properties || {}).length;
  }
  /**
   * 伸缩查询条件
   */
  expandToggle(): void {
    this._$expand = !this._$expand;
    this.sf?.setValue('/_$expand', this._$expand);
  }

  ngOnInit() {
    this.initSF();
    this.initST1();
    this.initST2();
  }

  initSF() {
    this.schema = {
      properties: {
        _$expand: { type: 'boolean', ui: { hidden: true } },
        name: {
          type: 'string',
          title: '提交人'
        },
        name1: {
          type: 'string',
          title: '企业管理员'
        },
        name2: {
          type: 'string',
          title: '角色'
        },
        name3: {
          type: 'string',
          title: '问题类型',
          ui: {
            visibleIf: {
              _$expand: (value: boolean) => value
            }
          }
        },
        name4: {
          type: 'string',
          title: '状态',
          ui: {
            visibleIf: {
              _$expand: (value: boolean) => value
            }
          }
        }
      }
    };
    this.ui = {
      '*': {
        grid: { span: 8, gutter: 4 }
      }
    };
  }

  initST1() {
    this.columns1 = [
      {
        title: '提交人',
        index: 'name1'
      },
      {
        title: '企业管理员',
        index: 'name1'
      },
      {
        title: '手机号',
        index: 'name1'
      },
      {
        title: '角色',
        index: 'name1'
      },
      {
        title: '问题类型',
        index: 'name1'
      },
      {
        title: '描述或建议',
        index: 'name1'
      },
      {
        title: '状态',
        index: 'name1'
      },
      {
        title: '提交时间',
        index: 'name1'
      },
      {
        title: '操作',
        className: 'text-center',
        buttons: [
          {
            text: '详情',
            click: (_record, _modal, _instance) => this.partnerView(_record)
          },
          {
            text: '处理',
            click: (_record, _modal, _instance) => this.partnerView(_record)
          }
        ]
      }
    ];
  }

  initST2() {
    this.columns2 = [
      {
        title: '提交人',
        index: 'name1'
      },
      {
        title: '客户名称',
        index: 'name1'
      },
      {
        title: '认领备注',
        index: 'name1'
      },
      {
        title: 'CRM状态',
        index: 'name1'
      },
      {
        title: '平台审核状态',
        index: 'name1'
      },
      {
        title: '提交时间',
        index: 'name1'
      },
      {
        title: '操作',
        className: 'text-center',
        buttons: [
          {
            text: '详情',
            click: (_record, _modal, _instance) => this.channelView(_record)
          },
          {
            text: '审核',
            click: (_record, _modal, _instance) => this.channelView(_record)
          }
        ]
      }
    ];
  }

  partnerView(record: STData) {
    this.router.navigate(['/partner/advice-feedback/detail'], { queryParams: {} });
  }

  channelView(record: STData) {
    this.router.navigate(['/partner/advice-feedback/detail'], { queryParams: {} });
  }
  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
  }
  search() {
    // this.st1?.load(1);
  }

  tabChange(index: any) {
    console.log(index);
    switch (index) {
      case 0:
        this.initST1();
        break;
      case 1:
        this.initST2();
        break;
      default:
        break;
    }
  }
}
